import React, { useState } from 'react';
import { Modal, Button, Input, Form } from 'antd';
import http from '../../../services/http'

const { TextArea } = Input;

const Add = (props) => {
    const [visible, setVisible] = useState(false);
    const [stan_name,setStan_name] = useState('');
    const [stan_unild,setStan_unild] = useState('');
    const [stan_standardUnit,setStan_standardUnit] = useState('');
    const [stan_upper,setStan_upper] = useState('');
    const [stan_lower,setStan_lower] = useState('');
    const [stan_normalMsg,setStan_normalMsg] = useState('');
    const [stan_upMsg,setStan_upMsg] = useState('');
    const [stan_lowerMsg,setStan_lowerMsg] = useState('');

    

    return (
        <>
            <Button type="primary" onClick={() => setVisible(true)}>
                添加
            </Button>
            <Modal
                title="新增体检指标"
                centered
                visible={visible}
                onOk={() => {
                    console.log(stan_name,stan_unild,stan_standardUnit,stan_upper,stan_lower,stan_normalMsg,stan_upMsg,stan_lowerMsg)
                    http({
                        url:'/addstandard',
                        method:'post',
                        data:{
                            stan_unild:stan_unild,
                            stan_name:stan_name,
                            stan_standardUnit:stan_standardUnit,
                            stan_upper:stan_upper,
                            stan_lower:stan_lower,
                            stan_normalMsg:stan_normalMsg,
                            stan_upMsg:stan_upMsg,
                            stan_lowerMsg: stan_lowerMsg
                        }
                    }).then((res)=>{
                        console.log(res)
                        if(res){
                            console.log(res);
                            setVisible(false);
                            window.location.href='http://localhost:3000/indexManagement'
                        }
                    })
                    
                }
                }
                onCancel={() => setVisible(false)}
                width={800}
            >
                
                    <Form labelCol={{ span: 3, }}>
                        <Form.Item label="标准指标名称" name="username1" rules={[{ required: true, },]}>
                            <Input values={stan_name} onChange={(e)=>{
                                setStan_name(e.target.value)
                            }}/>
                        </Form.Item>
                        <Form.Item label="套餐ID" name="套餐ID" rules={[{ required: true, message: '套餐ID仅支持数字类型' },]}>
                            <Input values={stan_unild} onChange={(e)=>{
                                setStan_unild(e.target.value)
                            }}/>
                        </Form.Item>
                        <Form.Item label="指标单位" name="username3" rules={[{ required: true, },]}>
                            <Input values={stan_standardUnit} onChange={(e)=>{
                                setStan_standardUnit(e.target.value)
                            }}/>
                        </Form.Item>
                        <Form.Item label="参考上限" name="username4" rules={[{ required: true, },]}>
                            <Input values={stan_upper} onChange={(e)=>{
                                setStan_upper(e.target.value)
                            }}/>
                        </Form.Item>
                        <Form.Item label="参考下限" name="username5" rules={[{ required: true, },]}>
                            <Input values={stan_lower} onChange={(e)=>{
                                setStan_lower(e.target.value)
                            }}/>
                        </Form.Item>

                        <Form.Item label="正常提示" name="username6" rules={[{ required: true, },]}>
                            <TextArea values={stan_normalMsg} onChange={(e)=>{
                                setStan_normalMsg(e.target.value)
                            }} rows={4} />
                        </Form.Item>

                        <Form.Item label="偏高提示" name="username7" rules={[{ required: true, },]}>
                            <TextArea values={stan_upMsg} onChange={(e)=>{
                                setStan_upMsg(e.target.value)
                            }} rows={4} />
                        </Form.Item>

                        <Form.Item label="偏低提示" name="username8" rules={[{ required: true, },]}>
                            <TextArea values={stan_lowerMsg} onChange={(e)=>{
                                setStan_lowerMsg(e.target.value)
                            }} rows={4} />
                        </Form.Item>
                    </Form>
                
            </Modal>
        </>
    );
};

export default Add;